<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        form {
            width: 240px;
            margin: 200px auto;
        }

        input,
        button {
            width: 240px;
            height: 36px;
            font-size: 18px;
            box-sizing: border-box;
            border: 1px solid #ccc;
            outline: 0;
            border-radius: 10px;
        }

        input {
            padding: 10px;
        }

        button {
            background: pink;
            border: 0;
            color: #fff;
        }

        span {
            display: block;
            padding-left: 10px;
            font-size: 14px;
        }
    </style>
</head>

<body>
    <form action="leg.php">
        <p>
            <input type="text" placeholder="昵称" id="uner">
            <span></span>
        </p>
        <p>
            <input type="password" placeholder="密码" id="pwd">
            <span></span>
        </p>
        <p>
            <input type="tel" placeholder="电话" id="tel">
            <span></span>
        </p>
        <button type="submit">登录</button>
    </form>

    <script src="jquery.js"></script>

    <script>


        function pas(a, b, c, d, e) {
            var f = $(a).val().length;
            window.pass = true;
            if (f >= b && f <= c) {
                $(a).css('border', '1px solid #0a0');
                $(a).next().text(d).css('color', '#0a0');
            } else {
                $(a).css('border', '1px solid #f00');
                $(a).next().text(e).css('color', '#f00');
                pass = false;
            }
            console.log(f);
        }
        $('form').on('submit', function () {
            pas('#uner', 3, 6, '昵称格式正确', '昵称格式错误');
            pas('#pwd', 6, 12, '密码格式正确', '密码格式错误');
            pas('#tel', 11, 11, '手机号格式正确', '请输入11位手机号');
            return pass;
        });

    </script>
</body>

</html>